package pf.springBoot.springBootSSO.configuration;

//import com.perfect.demo.interceptor.AuthorizeInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
/*import com.perfect.logistics.configuration.pojo.DeftConfig;
import com.perfect.logistics.configuration.pojo.ErrorPageConfig;
import com.perfect.logistics.initialize.WebInitializeService;
import com.perfect.logistics.interceptor.AuthorizeInterceptor;
import com.perfect.logistics.interceptor.DSHolderInterceptor;
import com.perfect.logistics.interceptor.ErrorPageInterceptor;
import org.springframework.beans.factory.annotation.Autowired;*/
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import pf.springBoot.springBootSSO.interceptor.MvcMenuFilterInterceptor;
import pf.springBoot.springBootSSO.interceptor.UserAuthorizeAttribute;

import java.util.ArrayList;
import java.util.List;
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.boot.web.servlet.support.ErrorPageFilter;
//import org.springframework.context.annotation.Bean;
//import org.springframework.web.servlet.config.annotation.CorsRegistry;

@Configuration
public class SpringMVCConfigure /*    @Autowired(required = false)
    private DeftConfig deftConfig;
    @Autowired(required = false)
    private ErrorPageConfig errorPageConfig;
    @Autowired(required = false)
    private WebInitializeService webInitializeService;*/
    implements WebMvcConfigurer {


//
//    @Bean
//    public ErrorPageFilter errorPageFilter() {
//        return new ErrorPageFilter();
//    }
//
//    @Bean
//    public FilterRegistrationBean<ErrorPageFilter> errorPageFilterRegistration() {
//        FilterRegistrationBean<ErrorPageFilter> registration = new FilterRegistrationBean<ErrorPageFilter>();
//        registration.setFilter(errorPageFilter());
//        registration.setEnabled(false);
//        return registration;
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 默认错误页面拦截器处理
        //InterceptorRegistration error = registry.addInterceptor(new ErrorPageInterceptor(deftConfig, errorPageConfig));
        // 排除配置
        //error.excludePathPatterns(deftConfig.getStaticPrefix() + "**");
        // 拦截配置
        //error.addPathPatterns("/**");
//        List<HandlerInterceptor> intercepter = webInitializeService.initWebMVCInterceptor();
        List<HandlerInterceptor> interceptors = new ArrayList<>();
//        interceptors.add(new AuthorizeInterceptor());     
        interceptors.add(new UserAuthorizeAttribute());//benjamin 
        interceptors.add(new MvcMenuFilterInterceptor()); 
        for (HandlerInterceptor interceptor : interceptors) {
            InterceptorRegistration addInterceptor = registry.addInterceptor(interceptor);
            // 排除配置
            addInterceptor.excludePathPatterns(
            		"/static/**","/templates/**",
            		"/css/**","/js/**","/images/**",
            		"/User/Login","/User/PostLogin","/User/LoginSSO" //必要时需增加注册页面的地址
            		);
            // 拦截配置
            addInterceptor.addPathPatterns("/**");
        }         
//        registry.addInterceptor(new UserAuthorizeAttribute())
//        .addPathPatterns("/**")
////        .excludePathPatterns("/test/login")
//        .excludePathPatterns("*User/Login*");
    }
    
//    /*
//     * 为了ajax跨域
//     * https://www.cnblogs.com/diandianquanquan/p/10607102.html
//     */
//    @Override 
//
//    public void addCorsMappings(CorsRegistry registry) { 
//
//        registry.addMapping("/**") 
//
//                .allowedOrigins("*") 
//
//                .allowCredentials(true) 
//
//                .allowedMethods("GET", "POST", "DELETE", "PUT") 
//
//                .maxAge(3600); 
//
//    } 
    
   /* @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
//        registry.addResourceHandler(deftConfig.getStaticPrefix()+ "**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }*/
}

